import type { PayInfoData } from '@/api/membership/types';
import { SourceTypeEnum } from '@/enums/contactsEnum';
import { ApplyTypeEnum } from '@/enums/membershipEnum';
import {
  OrderAuditStateEnum,
  OrderPayStateEnum,
  OrderStateEnum,
  OrderTypeEnum,
  OrderRefundStatusEnum,
  OrderpayMode,
  PayChannelCodeEnum,
  GroupChatStateEnum,
} from '@/enums/orderEnum';
import type { FindActivityArrangeListResult, IActivityListResData, manualSign, registerType } from '../activity/types';
import type { ActivityTypeEnum, ApprovalStatusEnum, SignStatusEnum, SignTypeEnum, TicketTypeEnum } from '@/enums/activityStatusEnum';
import type { IQuery } from '../indexTypes';

export interface CreateOrderData {
  orderType: OrderTypeEnum;
  memberLeadingId: number;
}

export interface MemberContactsVo {
  memberLeadingId: number;
  leadingId: number;
  levelId: number;
  levelName: string;
  typeId?: any;
  typeName?: any;
  leadingName?: string;
  leadingAvatar?: string;
  leadingSocialPosition: string;
  memberId: number;
  orgCompanyId: number;
  companyName: string;
  companyLogo: string;
  companyAddressStr: string;
  companyMainBusiness: string;
  companyMainBusinesList: string[];
  companyFoundTime?: string;
  tenantId: number;
  orgTenantName?: string;
  applyType: ApplyTypeEnum;
  currentDistance?: string;
  distance?: string;
  memberState: number;
  attention: boolean;
  unlockLeading: boolean;
  saasMerchantIsEnable: boolean;
  orderCode?: string;
}

export interface CreateSuborderResult {
  memberContactsVo: MemberContactsVo;
  // 总金额
  totalMoney: number;
  // 实缴金额
  payMoney: number;
  // 订单号
  orderCode: string;
  // 数据来源
  assType: SourceTypeEnum;
  memberLeadingId: number;
  remark: string;
  groupChatState: GroupChatStateEnum

  /** 会内审核状态 */
  orgAuditStatus: OrderAuditStateEnum;
  orgName: string;
  orgTenantId: number;
  orglogo: string;
  orgAuditReason: string;

  /** 会外审核状态 */
  toOrgAuditStatus: OrderAuditStateEnum;
  toOrgName: string;
  toOrgTenantId: number;
  toOrgLogo: string;
  toOrgAuditReason: string;
}

export interface CreateOrderResult {
  id: number;
  createBy: number;
  createTime: string;
  updateBy: number;
  updateTime: string;
  deleted: boolean;
  tenantId?: any;
  orderCode: string;
  orderType: string;
  payTime?: any;
  appUserId: number;
  wxOpenId: string;
  payMode: OrderpayMode;
  paymentDocument?: any;
  totalMoney: number;
  payMoney: number;
  remark?: any;
  userName: string;
  userPhone: string;
  sourceTenantId: number;
  paymentEndTime: string;
  subMchind: string;

  refundStatus: OrderRefundStatusEnum;
  orderState: OrderStateEnum;
  payState: OrderPayStateEnum;

  /** 通过payCode 查询支付相关参数 */
  payCode: string;
}

export interface ToPayData {
  /** === payCode */
  paymentOrderNum: string;
  payChannelCode: PayChannelCodeEnum;
  terminal: 'APPLET';
}

export interface ToPayResult {
  prePayTn: string;
}

export interface OrderDetails {
  id: number;
  orderCode: string;
  orderType: OrderTypeEnum;
  payCode: string;
  payTime?: string;
  appUserId: number;
  payMode: OrderpayMode;
  totalMoney: number;
  payMoney: number;
  remark: string;
  userName: string;
  userPhone: string;
  sourceTenantId: number;
  paymentEndTime: string;
  createTime: string;
  refundStatus: OrderRefundStatusEnum;
  orderState: OrderStateEnum;
  payState: OrderPayStateEnum;
  /** 是否可以重新发起订单 */
  isSubmitOrder: boolean;
  /** 待支付剩余时间(秒) */
  expireSecond: number
}

export interface UnlockOrderDetailResult extends OrderDetails {
  suborder: CreateSuborderResult;
}

export interface GetContactInformationResult {
  phone: string;
  wechatId: string;
  email: string;
}

export interface MembershipOrderDetailsResult extends OrderDetails {
  suborder: PayInfoData;
}

export interface MyOrderListData extends IQuery {
  orderState: OrderStateEnum
  orderTypeList: OrderTypeEnum[]
}

export interface MyOrderListReslut {
  id: number;
  orderCode: string;
  orderType: OrderTypeEnum;
  payState: number;
  payCode: string;
  payTime: string;
  appUserId: number;
  wxOpenId: string;
  payMode: OrderpayMode;
  refundStatus: OrderRefundStatusEnum;
  totalMoney: number;
  payMoney: number;
  remark: string;
  userName: string;
  userPhone: string;
  createTime: string;
  orderState: OrderStateEnum;
  tenantId: string;
  orgName: string;
  sourceTenantId: string;
  sourceOrgName: string;

  productName: string;
  productPicture: string;
  productCount: number
}


export type ActivityShortDetailVo = {
  activityType: ActivityTypeEnum;
  activityId: number
  manualSign: manualSign;
  /** 是否显示签到按钮 0 不显示 1 显示 */
  isSign: 0 | 1
} & Pick<IActivityListResData, 'title' | 'startTime' | 'addressName' | 'coverUrl' | 'activityStatus' | 'address' | 'longitude' | 'latitude'>

/**
 * @description 活动订单中的报名信息
 * @date 02/07/2024
 * @export
 * @interface ActivityRegisterTicketUnion
 */
export interface ActivityRegisterTicketUnion {
  /** 活动ID */
  activityUnionId: number;
  /** 报名ID */
  id: number
  approvalStatus: ApprovalStatusEnum
  registerType: registerType
  createTime: string;
  /** 审核人姓名 */
  verifyName: string;
  /** 报名审核时间 */
  verifyTime: string

  /** 券号 */
  consumeNo: string
  /** 券码 */
  consumeNoUrl: string
  /** 排座信息 */
  arrangeVoList: FindActivityArrangeListResult[]
  avatar: string
  personName: string
  personTel: string
  ticketName: string
  /** 取消人姓名 */
  cancelPersonName?: string
  /** 取消人电话 */
  cancelPersonTel?: string
  /** 取消时间 */
  cancelTime?: string
  /** 代报名人姓名 */
  gmatName: string
  /* 代报名人电话 */
  gmatPhone: string
  /** 票种类型 */
  ticketType: TicketTypeEnum;

  /**签到人 */
  replaceSignPersonName: string;
  /**签到手机号 */
  replaceSignPersonPhone: string;
  /**签到单位名称 */
  replaceSignCompanyName: string;
  /**签到单位职务 */
  replaceSignCompanyPosition: string;
  /**签到方式 */
  signType: SignTypeEnum;
  /**签到时间 */
  signTime: string;
  /** 手写签名图片 */
  signImg: string;
  /** 签到状态 */
  signStatus: SignStatusEnum
  /** 审核驳回原因 */
  remarks?: string
  /** 取消记录ID */
  cancelRecordId?: number
  /** 取消原因 */
  cancelReason?: string
  totalMoney: number
  payMoney: number
  totalDiscountMoney: number
}

export interface ActivityRegisterInfoItem {
  id: number
  personName: string
  personTel: string
  remarks: string
  activityRegisterTicketUnion?: ActivityRegisterTicketUnion
}

export interface ActivityOrderDetailResult extends OrderDetails {
  suborder: {
    activityShortDetailVo: ActivityShortDetailVo
    activityRegisterInfoList: ActivityRegisterInfoItem[]
    submitName: string
    submitPhone: string
    submitTime: string
    activityTicketName: string
    /** 总金额 */
    totalMoney: number
    /** 总优惠金额 */
    totalDiscountMoney: number
    /** 实付金额 */
    payMoney: number
  };
}